const express = require('express');
const multer = require('multer');
const cors = require('cors');

const upload = multer({
    storage: multer.diskStorage({
        destination: function (req, file, cb) {
            cb(null, './uploads');
        },
        filename: function (req, file, cb) {
            const uniqueSuffix =
                Date.now() + '-' + Math.round(Math.random() * 1e9);
            cb(null, file.fieldname + '-' + uniqueSuffix);
        },
    }),
});

const app = express();
app.use(cors({ origin: '*' }));
app.post('/upload', upload.single('file'), (req, res) => {
    console.log(req.file);
    res.send({ success: true });
});
app.listen(3001, () => {
    console.log('Server is running on port 3001');
});